﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StrategyPattern
{
    ///现金收费抽象类
    public abstract class CashSuper
    {
        public abstract double acceptCash(double money);
    }

    /// <summary>
    /// 正常收费类
    /// </summary>
    public class CashNormal : CashSuper
    {
        public override double acceptCash(double money)
        {
            return money;
        }
    }
    /// <summary>
    /// 打折收费
    /// </summary>
    public class CashRebate : CashSuper
    {
        private double moneyrebate = 1d;

        public CashRebate(double moneyrebate)
        {
            this.moneyrebate = moneyrebate;
        }

        public override double acceptCash(double money)
        {
            return money * moneyrebate;
        }
    }

    /// <summary>
    /// 返利收费
    /// </summary>
    public class CashRetutn : CashSuper
    {
        private double moneyCondition = 0.0d;
        private double moneyReturn = 0.0d;

        public CashRetutn(double moneyCondition, double moneyReturn)
        {
            this.moneyCondition = moneyCondition;
            this.moneyReturn = moneyReturn;
        }

        public override double acceptCash(double money)
        {
            double result = money;
            if (money >= moneyCondition)
            {
                result = money - Math.Floor(money / moneyCondition) * moneyReturn;
            }
            return result;
        }
    }

    /// <summary>
    /// 现金收费工厂类
    /// </summary>
    public class CashFactory
    {
        public static CashSuper createCashAccept(string type)
        {
            CashSuper cs = null;
            switch (type)
            {
                case "正常收费":
                    cs = new CashNormal();
                    break;
                case "满300返100":
                    CashRetutn crl = new CashRetutn(Convert.ToDouble("300"), Convert.ToDouble("100"));
                    cs = crl;
                    break;
                case "打8折":
                    CashRebate cr2 = new CashRebate(Convert.ToDouble("0.8"));
                    cs = cr2;
                    break;
                default:
                    break;
            }
            return cs;
        }
    }


}
